<?php

class Application_Form_Blog extends Zend_Form
{

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
    	
    	$this->setMethod('post');
    	
    	$this->addElement('text', 'BLEN_TITLE', array(
    		'label'			=> 'Blog Title:', 
    		'required' 		=> true, 
    		'filters'		=> array('StringTrim'), 
    		'validators'	=> array(
    			array('validator' => 'StringLength', 'options' => array(0, 100))
    		)
    	));
    	
    	$this->addElement('textarea', 'BLEN_DESC', array(
    		'label' 		=> 'Blog Description:', 
    		'required' 		=> true, 
    		'filters' 		=> array('StringTrim'), 
    		'validators'	=> array(
    			array('validator' => 'StringLength', 'options' => array(0, 2000))
    		)
    	));
    	
    	$this->addElement('select', 'BLST_ID', array(
    		'label'			=> 'Blog Status:', 
    		'required'		=> true, 
    		'RegisterInArrayValidator'	=> false 
    	));
    	
    	
    	$this->addElement('captcha', 'captcha', array(
    		'label'			=> 'Please enter the 5 letters displayed below:', 
    		'required' 		=> true, 
    		'captcha' 		=> array(
    			'captcha'	=> 'figlet', 
    			'wordLen' 	=> 5, 
    			'timeout'	=> 300
    		)
    	));
    	
    	/*
    	$captcha = new Zend_Form_Element_Captcha(array('name' => 'captcha'));
    	$captcha->setAttrib('timeout', '300')
    		->setAttrib('wordLen', '6')
    		->setAttrib('height', '80')
    		->setAttrib('font', '/public/arial.tff')
    		->setAttrib('imgDir', '/public/images/captcha')
    		->removeDecorator('HtmlTag')
    		->removeDecorator('Label');
    	*/
    	/*
    	$this->addElement('captcha', 'captcha', array(
    		'label'			=> 'Please enter the 6 letters displayed below:', 
    		'required'		=> true, 
    		'captcha'		=> array(
    			'captcha'		=> 'Image', 
    			'wordLen'		=> 6, 
    			'timeout'		=> 300, 
    			'font'			=> APPLICATION_PATH . './arial.ttf', 
    			'imgDir' 		=> '../../../images/captcha/')));
    	*/
    	/*
    	$captcha = $this->getElement('captcha');
    	$captcha->setAttrib('timeout', '300')
    		->setAttrib('wordLen', '6')
    		->setAttrib('height', '80')
    		->setAttrib('font', APPLICATION_PATH . '/arial.tff')
    		->setAttrib('imgDir', APPLICATION_PATH . '/images/captcha')
    		->removeDecorator('HtmlTag')
    		->removeDecorator('Label');
    	*/
    	
    	
    	$this->addElement('submit', 'submit', array(
    		'ignore'		=> true, 
    		'label' 		=> 'Save Changes'
    	));
    	
    	/*
    	$this->addElement('hash', 'csrf', array(
    		'ignore' 		=> true
    	));
    	*/
    	/*
    	$s = new Zend_Session_Namespace('csrf');
    	$s->setExpirationSeconds(300);
    	$s->setExpirationHops(5);
    	*/
    	/*
    	$token = new Zend_Form_Element_Hash(array('name' => 'csrf'));
    	$token->setSalt(md5('Greenparot'))
    		->setTimeout(3600)
    		->removeDecorator('HtmlTag')
    		->removeDecorator('Label');
    		
    	$this->addElement($token);
    	
    	echo $token->getSessionName();
    	*/
    	
    	//$hash = new Zend_Form_Element_Hash('csrf');
    	//$this->addElement('hash', 'csrf', array('salt' => 'unique'));
		//$form->addElement('hash', 'csrf', array('salt' => 'unique'));
		
    	
    	$nameSpace = new Zend_Session_Namespace('csrf');
    	$nameSpace->setExpirationSeconds(900);
    	$nameSpace->csrf = $hash = md5(uniqid(rand(), 1));
    	$csrf = $this->addElement('hidden', 'csrf')->getElement('csrf');
    	
    	$csrf->setValue($hash)
    		->setRequired('true')
    		->removeDecorator('HtmlTag')
    		->removeDecorator('Label');
    		
    	//$this->addElement('hidden', 'csrf');
    		
    	
    	$this->addElement('hidden', 'BLEN_ID');
    	
    }
    
    /*
    public function __construct($options = null)
    {
    	$this->addPrefixPath('Greenparot_Form_Element_', 'greenparot/form/element/', 'element');
    	parent::__construct($options);
    }
    */


}

